package com.hsmpay.mobile.service.user.impl;

import com.hsmpay.common.service.impl.MemcachedServiceSupport;
import com.hsmpay.common.util.system.Constant;
import com.hsmpay.mobile.service.user.RegisterCodeService;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * 注册用户手机验证码 业务接口实现类
 * 对应数据层 没有
 *
 * @param <Entity>
 * @param <Query>
 * @author 颜铃璋
 * @date 2013-1-6
 */
@Service("registerCodeService")
public class RegisterCodeServiceImpl<Entity extends Serializable, Query extends Object> extends MemcachedServiceSupport<Entity, Query> implements RegisterCodeService<Entity, Query> {

    public RegisterCodeServiceImpl() {
        EXPIRATION_TIME = Integer.parseInt(Constant.getAttribute("REGISTER_CODE_MEMCACHE_EXPIRE"));
    }

    /**
     * 保存手机验证码 到memcache
     *
     * @param mobile
     * @param code
     * @return
     * @throws Exception
     */
    public boolean savaRegisterCodeToMemcache(String mobile, String code) throws Exception {
        String key = new StringBuilder().append(REGISTER_CODE_KEY).append(mobile).toString();
        return setCacheData(key, code);
    }

    /**
     * 从memcache中取出 手机验证码
     *
     * @param mobile
     * @return
     * @throws Exception
     */
    public String getRegisterCodeToMemcache(String mobile) throws Exception {
        String key = new StringBuilder().append(REGISTER_CODE_KEY).append(mobile).toString();
        return (String) getCacheData(key);
    }
}
